//
//  SYS_SelectShipAddressVC.m
//  System_App
//
//  Created by 吴健 on 2017/12/6.
//  Copyright © 2017年 czy001. All rights reserved.
//

#import "SYS_SelectShipAddressVC.h"
#import "SYS_SelectShipAddressCell.h"

@interface SYS_SelectShipAddressVC ()
{
    IBOutlet SYS_TableView *tbv;
    NSArray *dataArray;
}
@end

@implementation SYS_SelectShipAddressVC

- (id)initWithDataArray:(NSArray *)array{
    if (self == [super init]) {
        dataArray = [NSArray arrayWithArray:array];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationBar];
    [self setUI];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -- setter and getter
- (void)setNavigationBar{
    self.title = @"选择发货地址";
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImage:@"SYS_Public_back" highImage:nil title:nil target:self action:@selector(backToPrevious)];
}

- (void)setUI{
    UIView *v_head = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 15)];
    tbv.tableHeaderView = v_head;
    
    UIView *v_foot = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 80)];
    UILabel *lb_title = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, SCREENWIDTH, 40)];
    lb_title.text = @"地址管理请在\"系统后台——商城设置——物流管理\"设置";
    lb_title.font = DSFONT_DETAIL;
    lb_title.textColor = WJCOLOR_GRAY;
    lb_title.numberOfLines = 0;
    lb_title.textAlignment = NSTextAlignmentCenter;
    [v_foot addSubview:lb_title];
    tbv.tableFooterView = v_foot;
    
}

#pragma mark -- touch and event
- (void)backToPrevious{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -- UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    AddressList *modle = dataArray[indexPath.row];
    if (self.shipAddressDidSelect) {
        NSString *address=[NSString stringWithFormat:@"%@ %@ %@ %@",modle.provinceName,modle.cityName,modle.areaName,modle.detailLocation];
        self.shipAddressDidSelect(address, modle.shipAddressId);
    }
    [self.navigationController popViewControllerAnimated:YES];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

#pragma mark -- UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"SYS_SelectShipAddressCell";
    SYS_SelectShipAddressCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [SYS_SelectShipAddressCell getSelectShipAddressCell];
    }
    AddressList *model = dataArray[indexPath.row];
    cell.indexPath = indexPath;
    cell.model = model;
    return cell;
}


@end
